package app.beit.finportal.service.convert;

import java.util.ArrayList;
import java.util.List;

import sun.misc.BASE64Encoder;
import app.beit.finportal.bean.SlidesBean;
import app.beit.finportal.entity.Slides;
import app.beit.finportal.utils.StringUtils;

public class SlidesConvert {

	/**
	 * Convert Entity To Bean
	 * @param entity
	 * @return NewsBean
	 */
	public static SlidesBean entityToBean(final Slides entity) throws Exception {
		final SlidesBean bean = new SlidesBean();
		
		bean.setId(entity.getId());
		bean.setName(entity.getName());
		bean.setCreatedBy(StringUtils.nullToEmpty(entity.getCreatedBy()));
		bean.setCreatedDate(entity.getCreatedDate());
		bean.setUpdatedBy(StringUtils.nullToEmpty(entity.getUpdatedBy()));
		bean.setUpdatedDate(entity.getUpdatedDate());
		
		bean.setDescription(StringUtils.nullToEmpty(entity.getDescription()));
		bean.setPicture(entity.getPicture());
		bean.setUrl(StringUtils.nullToEmpty(entity.getUrl()));
		bean.setStatus(entity.getStatus());
		bean.setPictureLocation(entity.getPictureLocation());
		
		bean.setCreatedAccount(AccountConvert.entityToBean(entity.getCreatedAccount()));
		bean.setUpdatedAccount(AccountConvert.entityToBean(entity.getUpdatedAccount()));
		
		bean.setStrPicture(new BASE64Encoder().encode(entity.getPicture()));
		
		return bean;
	}
	
	/**
	 * Convert Bean to Entity
	 * @param bean
	 * @return News
	 */
	public static Slides beanToEntity(final SlidesBean bean){
		final Slides entity = new Slides();

		entity.setId(bean.getId());
		entity.setName(bean.getName());
		entity.setCreatedBy(StringUtils.nullToEmpty(bean.getCreatedBy()));
		entity.setCreatedDate(bean.getCreatedDate());
		entity.setUpdatedBy(StringUtils.nullToEmpty(bean.getUpdatedBy()));
		entity.setUpdatedDate(bean.getUpdatedDate());

		entity.setDescription(StringUtils.nullToEmpty(bean.getDescription()));
		entity.setPicture(bean.getPicture());
		entity.setUrl(StringUtils.nullToEmpty(bean.getUrl()));
		entity.setStatus(bean.getStatus());
		entity.setPictureLocation(bean.getPictureLocation());
		
		return entity;
	}

	/**
	 * Convert List Entity to List Bean
	 * @param entities
	 * @return List NewsBean
	 */
	public static List<SlidesBean> entityToBean(final List<Slides> entities) throws Exception{
		final List<SlidesBean> beans = new ArrayList<SlidesBean>();
		
		for(final Slides entity : entities){
			beans.add(SlidesConvert.entityToBean(entity));
		}
		
		return beans;
	}
	
	/**
	 * Convert List Bean to List Entity
	 * @param beans
	 * @return List News
	 */
	public static List<Slides> beanToEntity(final List<SlidesBean> beans){
		final List<Slides> entities = new ArrayList<Slides>();
		
		for(final SlidesBean bean : beans){
			entities.add(SlidesConvert.beanToEntity(bean));
		}
		
		return entities;
	}
	
}
